package javaee.synchronize;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author tongchen
 * @create 2023-04-12 0:11
 */
public class MyExecutor {
    //使用线程池创建线程
    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5, 10, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
        for (int i = 0; i <10 ; i++) {
            int j=i;
            threadPoolExecutor.submit(()->{
                System.out.println(Thread.currentThread().getName()+"执行任务"+j);
            });
        }
    }
}
